<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<section [formGroup]="resourcesFormGroup">
  <div class="flex flex-row items-center justify-start">
    <div class="max-w-30% flex-full">
      <mat-label translate>device-profile.lwm2m.resource-label</mat-label>
    </div>
    <div class="checkbox-column-title max-w-10% flex-full">
      <mat-label translate>device-profile.lwm2m.attribute-label</mat-label>
    </div>
    <div class="checkbox-column-title max-w-10% flex-full">
      <mat-label translate>device-profile.lwm2m.telemetry-label</mat-label>
    </div>
    <div class="checkbox-column-title max-w-10% flex-full">
      <mat-label translate>device-profile.lwm2m.observe-label</mat-label>
    </div>
    <div class="flex-1">
      <mat-label translate>device-profile.lwm2m.key-name</mat-label>
    </div>
  </div>
  <mat-divider></mat-divider>
  <div formArrayName="resources"
    *ngFor="let resourceLwM2M of resourcesFormArray.controls; let $index = index; trackBy: trackByParams">
    <div [formGroupName]="$index" class="resource-list flex flex-row items-center justify-start">
      <div class="resource-name max-w-30% flex-full">
        #{{resourceLwM2M.get('id').value}} <span class="name">{{resourceLwM2M.get('name').value}}</span>
      </div>
      <div class="flex max-w-10% flex-full items-center justify-center">
        <mat-checkbox formControlName="attribute" color="warn">
        </mat-checkbox>
      </div>
      <div class="flex max-w-10% flex-full items-center justify-center">
        <mat-checkbox formControlName="telemetry" color="primary">
        </mat-checkbox>
      </div>
      <div class="flex max-w-10% flex-full items-center justify-center">
        <mat-checkbox class="max-w-10% flex-full" formControlName="observe" color="primary"
                      matTooltip="{{ 'device-profile.lwm2m.edit-observe-select'  | translate }}"
                      [matTooltipDisabled]="disabled || !isDisabledObserve($index)"
                      matTooltipPosition="above">
        </mat-checkbox>
      </div>
      <mat-form-field class="max-w-33% flex-full">
        <input matInput type="text" formControlName="keyName" required>
        <mat-error *ngIf="resourceLwM2M.get('keyName').hasError('required') ||
                            resourceLwM2M.get('keyName').hasError('pattern')">
          {{ 'device-profile.lwm2m.key-name-required' | translate }}
        </mat-error>
      </mat-form-field>
      <span class="flex-1"></span>
      <tb-profile-lwm2m-attributes
        formControlName="attributes"
        [isAttributeTelemetry]="isDisabledObserve($index)"
        isResource="true"
        [modelName]="getNameResourceLwm2m(resourceLwM2M.value)">
      </tb-profile-lwm2m-attributes>
    </div>
  </div>
</section>
